package org.point.service.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.point.common.service.impl.BaseServiceImpl;
import org.point.common.util.DoPage;
import org.point.dao.ConvertRuleMainDao;
import org.point.dao.CreditsTypeDao;
import org.point.domain.ConvertRuleMain;
import org.point.service.ConvertRuleMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @ClassName: ConvertRuleMainServiceImpl  
 * @Description: TODO(兑换规则业务实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午4:02:01  
 *
 */
@Service("convertRuleMainService")
public class ConvertRuleMainServiceImpl extends BaseServiceImpl<ConvertRuleMain, Serializable> implements ConvertRuleMainService {
	
	@Autowired
	private ConvertRuleMainDao dao;
	
	public DoPage<ConvertRuleMain> searchCRMForMem(DoPage<ConvertRuleMain> page) {
		// 根据page参数查询记录
		List<ConvertRuleMain> records = dao.findCRMForMem(page);
		page.setList(records);
		// 根据page参数查询记录条数
		Integer totalRecords = dao.countCRMForMem(page);
		page.setTotalRecords(totalRecords);
		return page;
	}

	public Integer countCRMForMem(DoPage<ConvertRuleMain> page) {
		Integer result = dao.countCRMForMem(page);
		return result;
	}

	public Integer insertCRM(ConvertRuleMain record,String crmCode) {
		 Integer result = 0;
		if(record.getId()!=null){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", record.getId());
			Integer isdel = dao.delCRMbyId(map);
			record.setDelFlag(new Byte("0"));
			Integer insert = dao.insert(record);
			if(isdel+insert > 1){
				result = 1;
			}
		}else{
			record.setDelFlag(new Byte("0"));
			record.setConvertId(crmCode);
		    result = dao.insert(record);
		}
		return result;
	}

	public Integer updStatus(Map<String, Object> map) {
		Integer result = dao.updStatus(map);
		return result;
	}

	public Integer updDelflag(Map<String, Object> map) {
		Integer result = dao.updDelflag(map);
		return result;
	}

	public ConvertRuleMain getCTByCRMID(Map<String, Object> map) {
		ConvertRuleMain records = dao.searchForCon(map);
		return records;
	}

	public Integer deleteCRM(Map<String, Object> map) {
		Integer result = dao.deleteCrm(map);
		return result;
	}

	
}
